﻿Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing


Public Class Site
    Inherits System.Web.UI.MasterPage
    Dim myconnection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("mercedesbenzconnectionstring").ConnectionString)
    Dim myda As OleDbDataAdapter = New OleDbDataAdapter("Select * from Events", myconnection)
    Dim ds As New DataSet
    Dim dsSelDate As DataSet


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        myda.Fill(ds, "AllTables")

    End Sub

    Protected Sub Calendar13_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar13.DayRender

        'this code below reads data from the database to show event dates

        'If the month is CurrentMonth
        If Not e.Day.IsOtherMonth Then
            Dim dr As DataRow
            For Each dr In ds.Tables(0).Rows
                'If EventDate is not Null
                If Not dr("date_and_time") Is DBNull.Value Then
                    Dim dtEvent As DateTime = dr("date_and_time").ToString
                    'If EventDate =CalendarDate
                    If dtEvent.Equals(e.Day.Date) Then
                        e.Cell.BackColor = Color.Chocolate
                    End If
                End If
            Next
            'If the month is not CurrentMonth then hide the Dates
        Else
            e.Cell.Text = ""
        End If

    End Sub

    Public Sub Calendar13_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar13.SelectionChanged
        Dim myconnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("mercedesbenzconnectionstring").ConnectionString)
        Dim myda As New OleDbDataAdapter("SELECT eventname, date_and_time FROM Events WHERE date_and_time = #" & Calendar13.SelectedDate & "#", myconnection)
        Dim dsSelDate As New DataSet()
        myda.Fill(dsSelDate)
        If dsSelDate.Tables(0).Rows.Count = 0 Then
            GridView1.Visible = False
        Else
            GridView1.Visible = True
            GridView1.DataSource = dsSelDate
            GridView1.DataBind()
        End If
    End Sub

End Class